#pragma once

#include <QObject>
#include"mtf.h"

class DataBase : public QObject
{
	Q_OBJECT

public:
	DataBase(QString ProductType = "");
	~DataBase();
	void CreateProjectDataConnection(QString connetionName);
	void CreateTable();
	void InitTable();
	void CreateWorkRateTableHeader(QString ConnName, QString TableName);
	void WriteWorkRateDB(QString ConnName,INT64 totalTime,
		INT64 workTime, INT64 waitTime, INT64 WarningTime, INT64 faultTime, int outPut,
		double workRate, double waitRate, double faultRate,
		INT64 totalWorkTime, INT64 totalWaitTime, INT64 totalWarningTime, INT64 totalFaultTime, int totalOutPut,
		double totalWorkRate, double totalWaitRate, double totalFaultRate,
		int curPositingFail, int  TotalPositingFail);
	void CraeteLogTableHeader(QString ConnName, QString TableName);
	void WriteLogDB(QString TableName, int WarningNo, QString Warningtext);
	void removeConnection(QString connectionName);
	QString& GetSetLogCurTableName();
	QString& GetSetWorkRateCurTableName();
	void CleanUpOutdatedTables();

	void queryWorkRateSelectedShift(QString strDate, QString strShift, QVariantList& reTime, QVariantList& reUph, QVariantList& reAlert, QVariantList& reDowntime, QVariantList& reWaitting, QVariantList& reCorrection, QVariantList& tWork, QVariantList& tWaitting, QVariantList& talert, QVariantList& tDowntime, QVariantList& tOutPut);

	void queryLogSelectedShift(QString strDate, QString strShift, QVariantList& reCount, QVariantList& reNum, QVariantList& reText);

	void queryHistoryState(QStringList& strWorkRateNameList, QVariantList& tWork, QVariantList& tWaitting, QVariantList& talert, QVariantList& tDowntime);

public:
	QString m_ConfigDB;
	QString m_DataDB;
	QString  m_ProductType;
private:
	QString m_LogTableName;
	QString m_WorkRateTableName;
	std::mutex m_LogTableNameMutex, m_WorkRateTableNameMutex;
};
